<?php
/**
 * Created by PhpStorm.
 * User: chenxuyi
 * Date: 2017/12/20
 * Time: 下午4:46
 */

namespace App\Traits;

use App\Exceptions\ErrorCode;
use Illuminate\Http\Response;

trait Output
{
    /**
     * 组装输出的数据
     * output
     *
     * @param array  $data
     * @param string $msg
     * @param int    $code
     * @param int    $httpStatus
     *
     * @return \Illuminate\Http\JsonResponse
     * @author chenxuyi
     */
    protected function output($data = [], string $msg = '', int $code = ErrorCode::SUCCESS, int $httpStatus = Response::HTTP_OK)
    {
        $output = [
            'data' => $data,
            'code' => $code,
            'msg'  => $msg,
        ];

        return \response()->json($output, $httpStatus, [], JSON_UNESCAPED_UNICODE);
    }
}